Skip to content

fix prometheus: escape backslash and newline in label values - #1268

Closed
netliomax25-code wants to merge 1 commit into
userver-framework:developfrom
netliomax25-code:prometheus-label-escape
Closed

fix prometheus: escape backslash and newline in label values#1268
netliomax25-code wants to merge 1 commit into
userver-framework:developfrom
netliomax25-code:prometheus-label-escape

Conversation

@netliomax25-code

Copy link
Copy Markdown
Contributor
  1. DumpLabelsRaw escapes only " (to ') in Prometheus label values, leaving backslash and line feeds raw.
  2. A value ending in \ then escapes the closing quote so the rest of the line is pulled into the value, and an embedded line feed starts a new sample line.

Added AppendEscapedLabelValue to double \ and write line feeds as \n, matching how the Graphite and Solomon writers already neutralize these characters. Covered both cases with a regression test.

@netliomax25-code
netliomax25-code force-pushed the prometheus-label-escape branch from 04a29c2 to b28505f Compare June 29, 2026 07:46
@apolukhin

Copy link
Copy Markdown
Member

LGTM

@robot-magpie

robot-magpie Bot commented Jun 29, 2026

Copy link
Copy Markdown

Many thanks for the PR! @apolukhin is now importing your pull request into our internal upstream repository.

@robot-magpie

robot-magpie Bot commented Jul 29, 2026

Copy link
Copy Markdown

✅ This pull request is being closed because it has been successfully merged into our internal monorepository.
Your changes will be pushed to this repository soon. Thank you for your contribution!

@robot-magpie robot-magpie Bot closed this Jul 29, 2026
robot-piglet pushed a commit that referenced this pull request Jul 29, 2026
1. DumpLabelsRaw escapes only `"` (to `'`) in Prometheus label values, leaving backslash and line feeds raw.
2. A value ending in `\` then escapes the closing quote so the rest of the line is pulled into the value, and an embedded line feed starts a new sample line.

Added AppendEscapedLabelValue to double `\` and write line feeds as `\n`, matching how the Graphite and Solomon writers already neutralize these characters. Covered both cases with a regression test.

---

Pull Request resolved: #1268

Co-authored-by: “rootvector2” <“dxbnaveed.k@gmail.com”>
commit_hash:56d9bfdaee7a934cba9b149dbce1b6f2a205a104
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants